/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fait.ferm.persists;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Greg
 */
public class Cow_type extends PersistsObject {
    public String name;
    public int age;
    public int milk_yeild;
    public double price;
    public int milk_sort;
    public double medicaments;
    
    public Cow_type(int pId) throws Exception {
        super(pId);
        table = "cow_type";
        load();
    }
    
    @Override
    public void load() throws Exception {
        boolean notSuccessfully=true;
		if(id==-1) {
			throw new Exception("Объект "+table+" отсутствует в базе");
		}	
		try (Statement st = con.createStatement()) {
			String q = "SELECT name, age, milk_yeild, price, milk_sort, medicaments FROM "+table+" WHERE id = " + id;
			ResultSet rs = st.executeQuery(q);
			if(rs.next()){
				notSuccessfully=false;
				name = rs.getString("name");
                age = rs.getInt("age");
                milk_yeild = rs.getInt("milk_yeild");
                price = rs.getDouble("price");
                milk_sort = rs.getInt("milk_sort");
                medicaments = rs.getDouble("medicaments");
			}
			rs.close();
		}
		if(notSuccessfully) {
			throw new Exception("Объект "+table+" не загружен");
        }
    }

    @Override
    protected void update() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void createNew() throws SQLException, Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
